
var ust = {
    //解析queryString的字符串为对象
    parseQueryString:function(str) {
        if (str == '') {
            return;
        }
        str = $.trim(str).split('&');
        var newArr = {};
        $.each(str, function(i,n){
            var tmpArr = n.split('=');
            newArr[tmpArr[0]] = tmpArr[1];
        });
        this.data= newArr;
        return newArr;
    },
    /**
     * 验证数据是否为空
     * @param data
     * @returns {boolean}
     */
    isEmpty:function(data) {
        var isCorrect = true;
        if (typeof data == 'undefined' || data == '' || typeof data != 'object') {
            data = this.data;
        }
        ///console.log(data['keyword']);
        for (var i in data) {
            if (data[i] != '') {
                isCorrect = false;
                break;
            }
        }

        return isCorrect;
    },

    //页面
    page:{
        config:{
            delete_url: '',
            table_id:'#table-list',
            event_ob:'',
            table_ob:'',
            extra_params:{}
        },
        remove:function(config, successFn, failFn) {
            if (typeof config == 'function') {
                successFn = config;
                config = this.config;
            } else {
                config = $.extend(this.config, config);
            }

            try{
                that = this.config.event_ob;
                if (that == '') {
                    throw new Error('事件发生元素不存在');
                }
            } catch (e) {
                console.error(e);
                return false;
            }

            var id = that.attr('data-id');
            if (id) {

                del($.extend({id:id}, this.config.extra_params));
            } else {
                var checked = [];
                $('#table-list :checkbox:checked').each(function(i){
                    var v = $(this).val();
                    if (v > 0) {
                        checked.push(v);
                    }

                });
                if (checked.length == 0) {
                    layer.alert('请选择一条记录');
                } else {
                    del($.extend({id:checked}, this.config.extra_params));
                }

            }


            function del(params)
            {
                layer.confirm('您确定要删除吗？', {title:'提示'}, function(index){
                    $.post(config.delete_url, params, function(response){
                        if (response.success) {
                            if (typeof successFn == 'function') {
                                successFn(response);
                            } else {
                                config.table_ob.row(that.parent('tr')).remove().draw(false);
                            }

                        } else {
                            if (typeof failFn == 'function') {
                                failFn(response);
                            } else {
                                layer.alert(response.msg);
                            }

                        }
                        layer.close(index);
                    })
                })
            }

        }
    },

};